package com.sgb.trip.view.adapter;

import android.content.Context;

import androidx.databinding.DataBindingUtil;

import com.sgb.trip.R;
import com.sgb.trip.databinding.TripItemPassengerInfoBinding;
import com.sgb.trip.entity.PassengerInfoEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * Time:2021/6/18
 * Author:黄淋
 * Description:选择乘客时的adapter
 */
public class PassengerInfoChooseAdapter extends BaseRecycleAdapter<PassengerInfoEntity> {

    public PassengerInfoChooseAdapter(Context context, List<PassengerInfoEntity> datas) {
        super(context, R.layout.trip_item_passenger_info, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, PassengerInfoEntity entity) {
        TripItemPassengerInfoBinding binding = DataBindingUtil.bind(holder.itemView);

        if (entity.isSelected()) {
            binding.ivCheckBox.setBackground(context.getResources().getDrawable(R.mipmap.icon_square_select));
        } else {
            binding.ivCheckBox.setBackground(context.getResources().getDrawable(R.mipmap.icon_square_unselect));
        }
        binding.tvPassengerName.setText(entity.getName());
        binding.tvPassengerIdCard.setText("身份证 " + entity.getIdCard());
        binding.ivEditPassenger.setOnClickListener(view -> onClickItem.onEdit(entity));
    }

    public interface OnClickItem {
        void onEdit(PassengerInfoEntity entity);//编辑
    }

    OnClickItem onClickItem;

    public void setOnClickItem(OnClickItem onClickItem) {
        this.onClickItem = onClickItem;
    }
}
